package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    @Select("select id,username,password from t_user where username = #{username}")
    UserVO findUserByUsername(@Param("username") String username);

    @Select("select tr.id,tr.keyword from t_user_role tur,t_role tr where tur.role_id =tr.id and tur.user_id = #{uid}")
    List<RoleVO> findRoleInfoByUserId(@Param("uid") Integer uid);

    @Select("select tp.keyword " +
            "FROM t_role_permission trp , t_permission tp " +
            "WHERE trp.permission_id = tp.id " +
            "and trp.role_id = #{id}")
    List<Permission> findPermissionInfoByRoleId(@Param("id") Integer id);


    @Delete("delete from t_user_role where user_id=#{uid}")
    void deleteRole(Integer uid);

    @Insert("insert into t_user_role values(#{uid},#{rid})")
    void add(@Param("uid") Integer uid,@Param("rid") Integer rid);

    @Select("select * from t_user where id=#{id}")
    UserVO findUserVO(@Param("id") Integer id);

    @Select(("select role_id from t_user_role where user_id=#{uid}  "))
    List<Integer> fnndallrolelist(@Param("uid") Integer uid);

    @Select("select tm.id,tm.name,tm.linkUrl,tm.path,tm.icon,tm.level,tm.parentMenuId " +
            "FROM t_role_menu trm , t_menu tm " +
            "WHERE trm.menu_id = tm.id " +
            "and trm.role_id = #{rid}")
    List<Menu> findMenuInfoByRoleId(@Param("rid") Integer rid);
}
